package com.hjw.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Map;

public class JwtUtil {
    private static final String SIGNKEY = "hjw";
    //1. 生成token值
    public static String createToken(Map<String,Object> map){
        return Jwts.builder()
                .setClaims(map)
                .signWith(SignatureAlgorithm.HS256, SIGNKEY)
                .compact();
    }
    //2. 解析token值
    public static Claims parseToken(String token){
        return Jwts.parser()
                .setSigningKey(SIGNKEY)
                .parseClaimsJws(token)
                .getBody();
    }
}
